package com.tnstudio.shaketoopenapps;

import android.content.Context;
import android.content.SharedPreferences;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.ToggleButton;

public class MySharedPreferences {
	boolean bShake;
	int iSeek;
	String chooseApp;
	String choosePack;
	Context context;
	
	public boolean isbShake() {
		return bShake;
	}

	public void setbShake(boolean bShake) {
		this.bShake = bShake;
	}

	public int getiSeek() {
		return iSeek;
	}

	public void setiSeek(int iSeek) {
		this.iSeek = iSeek;
	}

	public String getChooseApp() {
		return chooseApp;
	}

	public void setChooseApp(String chooseApp) {
		this.chooseApp = chooseApp;
	}

	public String getChoosePack() {
		return choosePack;
	}

	public void setChoosePack(String choosePack) {
		this.choosePack = choosePack;
	}

	public Context getContext() {
		return context;
	}

	public void setContext(Context context) {
		this.context = context;
	}

	public MySharedPreferences(Context context) {
		super();
		this.context = context;
	}

	public MySharedPreferences(Context context,boolean bShake, int iSeek, String chooseApp,
			String choosePack) {
		super();
		this.bShake = bShake;
		this.iSeek = iSeek;
		this.chooseApp = chooseApp;
		this.choosePack = choosePack;
		this.context = context;
	}

	// SharedPreferences
	public void savingPreferences() {
		// tao doi tuong getSharedPreferences
		SharedPreferences pre = context.getSharedPreferences(
				SettingData.prefname, Context.MODE_PRIVATE);
		// tao doi tuong edit de thay doi
		SharedPreferences.Editor editor = pre.edit();
	
		// lua vao editor
		if (bShake != false)
			editor.putBoolean(SettingData.bShake, bShake);
		if (iSeek != 0)
			editor.putInt(SettingData.iSeek, iSeek);
		if (chooseApp.length() != 0)
			editor.putString(SettingData.chooseApp, chooseApp);
		if (choosePack.length() != 0)
			editor.putString(SettingData.choosePack, choosePack);
		// chap nhan lua xuong file
		editor.commit();
	}

	/**
	 * ham doc trang thai da lua truoc do
	 */
	public void restoringPreferences(ToggleButton _tbShake,
			SeekBar _sbHold, TextView _tvMyApp, TextView _tvValue) {
		SharedPreferences pre = context.getSharedPreferences(
				SettingData.prefname, Context.MODE_PRIVATE);

		bShake = pre.getBoolean(SettingData.bShake, false);
		iSeek = pre.getInt(SettingData.iSeek, 30);
		chooseApp = pre.getString(SettingData.chooseApp, "Messaging");
		choosePack = pre.getString(SettingData.choosePack, "com.android.mms");
		if (_tbShake != null)
			_tbShake.setChecked(bShake);
		if (_sbHold != null)
			_sbHold.setProgress(iSeek);
		if (_tvMyApp != null)
			_tvMyApp.setText(chooseApp + "");
		if (_tvValue != null)
			_tvValue.setText(iSeek + "");
	}

}
